package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ClientFollowUp;
import cn.wolfcode.crm.query.ClientQueryObject;
import cn.wolfcode.crm.service.IClientFollowUpService;
import cn.wolfcode.crm.service.IClientService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: crm
 * @description:
 * @author: Mr.chen
 * @create: 2018-07-07 22:06
 **/
@Controller
@RequestMapping("clientfollowup")
public class ClientFollowUpController {
    @Autowired
    private IClientService service;
    @Autowired
    private IClientFollowUpService clientFollowUpService;

    @RequestMapping("")
    @PermissionName("正式客户主页")
    @RequiresPermissions("clientfollowup:index")
    public String index() {
        return "clientfollowup/list";
    }

    @RequestMapping("list")
    @ResponseBody
    @RequiresPermissions("clientfollowup:list")
    @PermissionName("正式客户数据")
    public PageResult list(ClientQueryObject qo) {
        qo.setState1(0);
        PageResult result = service.query(qo);
        return result;
    }

    @RequestMapping("load")
    @ResponseBody
    @RequiresPermissions("clientfollowup:load")
    @PermissionName("客户信息加载")
    public JsonResult load() {
        JsonResult result = new JsonResult();
        try {
            clientFollowUpService.save();
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("正式员工数据加载失败");
        }
        return result;
    }

    @RequestMapping("query")
    @ResponseBody
    @RequiresPermissions("clientfollowup:query")
    @PermissionName("正式客户数据")
    public PageResult query(ClientQueryObject qo) {
        PageResult result = clientFollowUpService.query(qo);
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    @RequiresPermissions("clientfollowup:update")
    @PermissionName("客户信息更新")
    public JsonResult edit(ClientFollowUp entity) {
        JsonResult result = new JsonResult();
        try {
            clientFollowUpService.update(entity);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("正式员工数据更新失败");
        }
        return result;
    }
}
